package com.lagou.homework.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.lagou.homework.service.HelloService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.*;

@RestController
public class HelloController {

    @Reference
    private HelloService helloService;

    @RequestMapping("/hello")
    public String hello() {
        return helloService.hello("world",50000);
    }

    final ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(200, 500, 100L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(100000));

    @GetMapping("/helloTest")
    public void test() {
        new Timer().schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("调用方法 开始------");

                //执行methodA
                threadPoolExecutor.execute(() -> {
                    helloService.methodA();
                });

                //执行methodB
                threadPoolExecutor.execute(() -> {
                    helloService.methodB();
                });

                //执行methodC
                threadPoolExecutor.execute(() -> {
                    helloService.methodC();
                });

            }
        }, 0, 100);

    }

}
